/**
 * 首页Store
 */
import {
	GetNavBarApi,
	GetRecommendApi
} from '@/api/index.js'


export default {
	namespaced: true, //命名空间	
	state: () => ({

		navbar: [], //4.导航栏
		home: [], //首页
	}),
	mutations: {

		navBarMutation(state, value) { //4.导航栏mutation
			state.navbar = value
		},
		SET_HOME(state, value) {
			state.home = value
		}

	},
	actions: {
		async homeAction(context, e) {

			const {
				data
			} = await GetRecommendApi(e)

			context.commit('SET_HOME', data)


		},
		navBarAction(context) {
			return new Promise(async (reslove, reject) => {
				try {
					const res = await GetNavBarApi();
					if (res.code === 200) {
						context.commit('navBarMutation', res.data)
						reslove()
					}
				} catch (e) {
					//TODO handle the exception
					reject(e)
				}

			})
		}

	}
}